package my.test.csdn.weixin_43767015.basic.ch12.transaction.declarative.annotation.propagation.mandatory.base.service;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TxMandatoryService {
    /**
     * jdbc模版，用于操作数据库
     */
    @Resource
    private JdbcTemplate jdbcTemplate;

    /** 单独调用m2 */
    @Transactional(propagation = Propagation.MANDATORY)
    public void m2() {
        String sql = "insert into tx_study (name,age) values (?,?)";
        jdbcTemplate.update(sql, "TxMandatory", 30);
    }
}
